package com.example.easy.Service.Impl;

import com.example.easy.Dto.MessageBoard;
import com.example.easy.Service.myservice.MessageBoardServise;
import com.example.easy.mapper.MessageBoardMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MessageBoardServiselmpl implements MessageBoardServise {

    @Autowired
    MessageBoardMapper messageBoardMapper;


    //留言
    @Override
    public int insMessageBoard(MessageBoard messageBoard) {
        return messageBoardMapper.insMessageBoard(messageBoard);
    }


    //回复
    @Override
    public int reply(MessageBoard messageBoard) {

        if ((messageBoardMapper.selectnull(messageBoard.getNumber()))==1) {
            messageBoardMapper.reply(messageBoard);
            return 1;
        }else

        return 0;
    }


    //查看自己的留言
    @Override
    public  List<MessageBoard>  select(String username) {

        if (messageBoardMapper.select(username)!=null){
          return messageBoardMapper.select(username);
        }else
        return null;
    }

    //查看所有的留言
    @Override
    public List<MessageBoard> selectall() {

        return messageBoardMapper.selectall();
    }

    //查看未回复的留言
    @Override
    public List<MessageBoard> selectreply() {
        return messageBoardMapper.selectreply();
    }

    //查看某条留言的回复字段是否为空
    @Override
    public int selectnull(int number) {
        return messageBoardMapper.selectnull(number);
    }

}
